package com.kingdee.eas.hr.canon.cbase.app;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.framework.CoreBaseCollection;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.hr.canon.cbase.AdminOrgBaseCollection;
import com.kingdee.eas.hr.canon.cbase.AdminOrgBaseFactory;

public class AdminOrgBaseControllerBean extends
		AbstractAdminOrgBaseControllerBean {
	private static Logger logger = Logger
			.getLogger("com.kingdee.eas.hr.canon.cbase.app.AdminOrgBaseControllerBean");

	protected void _updateData(Context ctx, AdminOrgBaseCollection addColl,
			AdminOrgBaseCollection editColl, List removeList)
			throws BOSException, EASBizException {
		CoreBaseInfo info = null;
		CoreBaseCollection coll = new CoreBaseCollection();

		for (int i = 0, j = addColl.size(); i < j; i++) {
			info = addColl.get(i);
			coll.add(info);
		}
		if (coll.size() != 0) {
			AdminOrgBaseFactory.getLocalInstance(ctx).addnew(coll);
		}

		coll = new CoreBaseCollection();
		for (int i = 0, j = editColl.size(); i < j; i++) {
			info = editColl.get(i);
			coll.add(info);
		}
		if (coll.size() != 0) {
			AdminOrgBaseFactory.getLocalInstance(ctx).update(coll);
		}
		if (removeList.size() > 0) {
			Set set = new HashSet(Arrays.asList(removeList.toArray()));
			FilterInfo filter = new FilterInfo();
			filter.getFilterItems().add(
					new FilterItemInfo("id", set, CompareType.INCLUDE));
			AdminOrgBaseFactory.getLocalInstance(ctx).delete(filter);
		}
	}
}